﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

#if NETFX_CORE
using Windows.ApplicationModel.Resources;

#endif

namespace StyleMVVM.Validation.Impl.Fluent.Operators
{
	public class IsNotEmptyOperator<T> : UnaryOperator<T>
	{
		public IsNotEmptyOperator()
		{
			expressionMethod = GetType().GetTypeInfo().GetDeclaredMethod("Operate");
		}

#if NETFX_CORE
		public override string GenerateLogicStatement(ResourceLoader fluentResources)
		{
			return InternalGenerateMessage(fluentResources, "IsNotEmpty");
		}

		public override string GenerateErrorMessage(ResourceLoader fluentResources)
		{
			return InternalGenerateMessage(fluentResources, "CannotBeEmpty");
		}
#else
		public override string GenerateLogicStatement()
		{
			return InternalGenerateMessage(FluentResources.IsNotEmpty);
		}

		public override string GenerateErrorMessage()
		{
			return InternalGenerateMessage(FluentResources.CannotBeEmpty);
		}
#endif

		public static bool Operate(object leftValue)
		{
			if (leftValue is string)
			{
				return !string.IsNullOrEmpty(leftValue as string);
			}
			if (leftValue is IEnumerable)
			{
				foreach (object o in ((IEnumerable)leftValue))
				{
					return true;
				}
			}

			return false;
		}
	}
}